<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="itheima" uri="http://itheima.com/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
	session.setAttribute("role", "admin");
%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>校园百事通</title>
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="<%=basePath%>ckeditor/ckeditor.js"></script>
	
<!-- 引入js文件 -->
<!-- jQuery -->
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>
<script type="text/javascript">
//清空新建失物招领窗口中的数据
	function clearLosearticle() {
	    $("#new_goods").val("");
	    $("#new_content").val("");
	    var day = new Date();
	    $("#new_time").val(day.getFullYear()+"-"+day.getMonth()+"-"+day.getDate())
	}
	// 创建失物招领
	function addLosearticle() {
	CKEDITOR.instances.new_content.updateElement();
	$.post("<%=basePath%>losearticle/create.action",
	$("#new_losearticle_form").serialize(),function(data){
	        if(data =="OK"){
	            alert("失物招领创建成功！");
	            window.location.reload();
	        }else if(data=="goods"){
	            alert("失物招领创建失败！物品名称不能为空");
	            window.location.reload();
	        }else if(data=="content"){
	            alert("失物招领创建失败！详细信息不能为空");
	            window.location.reload();
	        }else{
	            alert("失物招领创建失败！");
	            window.location.reload();
	        }
	    });
	}
	// 通过id获取修改的失物招领信息
	function editLosearticle(id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>losearticle/getLosearticleById.action",
	        data:{"id":id},
	        cache:false,
	        success:function(data) {
	            $("#edit_id").val(data.id);
	            $("#edit_goods").val(data.goods);
	            $("#edit_Userid").val(data.userid);
	            $("#edit_types").val(data.types);
	            $("#edit_state").val(data.state);
	            $("#edit_times").val(data.times);
	            CKEDITOR.instances.edit_content.setData(data.content);
	        }
	    });
	}
    // 执行修改失物招领操作
	function updateLosearticle() {
	CKEDITOR.instances.edit_content.updateElement();
		$.post("<%=basePath%>losearticle/updateLosearticle.action",
		$("#edit_losearticle_form").serialize(),function(data){
			if(data =="OK"){
				alert("失物招领信息更新成功！");
				window.location.reload();
			}else if(data=="goods"){
	            alert("失物招领更新失败！物品名称不能为空");
	            window.location.reload();
	        }else if(data=="content"){
	            alert("失物招领更新失败！详细信息不能为空");
	            window.location.reload();
	        }else{
				alert("失物招领信息更新失败！");
				window.location.reload();
			}
		});
	}
	//更新状态
	function Updatestate(){
	    if(confirm('确实要更新状态吗?')) {
			$.post("<%=basePath%>losearticle/updateState.action",
		$("#edit_losearticle_form").serialize(),
			function(data){
				if(data =="OK"){
					alert("状态更新成功！");
					window.location.reload();
				}else{
					alert("状态更新失败！");
					window.location.reload();
				}
			});
		}
	}
	// 删除失物招领
	function deleteLosearticle(id) {
	    if(confirm('确实要删除该失物招领吗?')) {
	$.post("<%=basePath%>losearticle/delete.action",{"id":id},
	function(data){
	            if(data =="OK"){
	                alert("失物招领删除成功！");
	                window.location.reload();
	            }else{
	                alert("失物招领删除失败！");
	                window.location.reload();
	            }
	        });
	    }
	}
	// 通过id获取修改的管理员信息
	function editAdmin1(id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>admin/getAdminById.action",
	        data:{"id":id},
	        cache:false,
	        success:function(data) {;
	            $("#edit_id1").val(data.id);
	            $("#edit_adminName1").val(data.admin_name);
	        }
	    });
	}
	function updateadmin() {
		$.post("<%=basePath%>admin/update.action",
		$("#admin_form").serialize(),function(data){
			if(data =="OK"){
				alert("管理员信息更新成功！");
				window.location.reload();
			}else if(data=="name"){
				alert("管理员信息更新失败！名称不能为空");
				window.location.reload()
			}else if(data=="Aname"){
				alert("管理员信息更新失败！名称已存在");
				window.location.reload()
			}else if(data=="paw"){
				alert("管理员信息更新失败！旧密码错误");
				window.location.reload()
			}else{
				alert("管理员信息更新失败！");
				window.location.reload();
			}
		});
	}
	</script>
	</head>
	<body>
	
<div id="wrapper">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<h2 onclick="index()">校园百事通后台管理</h2> 
	</div>
	<!-- 导航栏右侧图标部分 -->
	<ul class="nav navbar-top-links navbar-right">
	    <!-- 邮件通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-envelope fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-messages">
				<li>
				    <a href="#">
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#">
				        <strong>查看全部消息</strong>
						<i class="fa fa-angle-right"></i>
				    </a>
				</li>
			</ul>
		</li>
		<!-- 邮件通知 end -->
		<!-- 用户信息和系统设置 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-user fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-user">
				<li><a data-toggle="modal" data-target="#adminEditDialog1" onclick= "editAdmin1(${Admin_SESSION.id})"><i class="fa fa-user fa-fw"></i>
				               管理员：${Admin_SESSION.admin_name}
				    </a>
				</li>
				<li class="divider"></li>
				<li>
					<a href="${pageContext.request.contextPath }/adminlogout.action">
					<i class="fa fa-sign-out fa-fw"></i>退出登录
					</a>
				</li>
			</ul> 
		</li>
		<!-- 用户信息和系统设置结束 -->
	</ul>
	
	<!-- 左侧显示列表部分 start-->
	<div class="navbar-default sidebar" role="navigation">
		<div class="sidebar-nav navbar-collapse">
			<ul class="nav" id="side-menu">
				<li class="sidebar-search">
					<div class="input-group custom-search-form">
					</div> 
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/user/list.action" class="active">
				      <i class="fa fa-user fa-fw"></i> 用户管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/admin/list.action" class="active">
				      <i class="fa fa-user fa-fw" ></i> 管理员管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/information/list.action" class="active">
				      <i class="fa fa-edit fa-fw"></i> 校园资讯管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/losearticle/list.action" class="active">
				      <i class="fa fa-dashboard fa-fw" ></i> 失物招领/寻物启事管理
				    </a>
				</li>
			</ul>
		</div>
	</div>
	<!-- 左侧显示列表部分 end--> 
  </nav>
    <!-- 客户列表查询部分  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">
				<a class="navbar-brand" href="<%=basePath%>losearticle/list.action">失物招领/寻物启事管理 </a></h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="get" 
				      action="${pageContext.request.contextPath }/losearticle/list.action">
					<div class="form-group">
						<label for="goods">物品名称</label> 
						<input type="text" class="form-control" id="goods" 
						                   value="${goods }" name="goods" />
					</div>
					<button type="submit" class="btn btn-primary">查询</button>
				</form>
			</div>
		</div>
		<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newLosearticleDialog" onclick="clearLosearticle()">新建</a>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">失物招领信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>编号</th>
								<th>物品名称</th>
								<th>类型</th>
								<th>状态</th>
								<th>发布人</th>
								<th>发布时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.id}</td>
									<td>${row.goods}</td>
									<td>${row.types}</td>
									<td>${row.state}</td>
									<td>${row.userid}</td>
									<td>${row.times}</td>
									<td>
										<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#losearticleEditDialog" onclick= "editLosearticle(${row.id})">修改</a>
										<a href="#" class="btn btn-danger btn-xs" onclick="deleteLosearticle(${row.id})">删除</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<itheima:page url="${pageContext.request.contextPath }/losearticle/list.action?goods1=1" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	<!-- 失物招领列表查询部分  end-->
</div>

<!-- 添加失物招领模态框 -->
<div class="modal fade" id="newLosearticleDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">添加失物招领信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_losearticle_form">
					<div class="form-group">
						<label for="new_goods" class="col-sm-2 control-label">物品名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_goods" placeholder="请输入物品名称" name="goods" />
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label" for="new_Userid" style="float:left;padding:7px 15px 0 27px;">发布人</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_Userid" value="管理员" name="userid" disabled="disabled">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label" for="new_time" style="float:left;padding:7px 15px 0 27px;">发布日期</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_time" name="time" disabled="disabled">
						</div>
					</div>
					<div class="form-group">
						<label for="new_types" class="col-sm-2 control-label">失物类型</label>
						<div class="col-sm-10">
							<select class="form-control" id="new_types" name="types">
								<option selected>失物</option>
								<option>寻物</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label" for="new_content" style="float:left;padding:7px 15px 0 27px;">详细信息</label> 
						<div class="col-sm-10">
							<textarea name="content" id="new_content" rows="70" cols="50">
							${data.article}
							</textarea>
							<script type="text/javascript">
							CKEDITOR.replace( 'new_content',{
							toolbar:[
								['Source','-','Save','NewPage','Preview','-','Templates'],
								['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
								['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
								['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
								'/',
								['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
								['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
								['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
								['Link','Unlink','Anchor'],
								['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
								'/',
								['Styles','Format','Font','FontSize'],
								['TextColor','BGColor'],
								['Maximize', 'ShowBlocks','-','About']
							]
							});
							</script>
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="addLosearticle()">保存</button>
			</div>
		</div>
	</div>
</div>
<!-- 修改失物招领模态框 -->
<div class="modal fade" id="losearticleEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改失物招领信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_losearticle_form">
					<input type="hidden" id="edit_id" name="id"/>
					<div class="form-group">
						<label for="edit_goods" class="col-sm-2 control-label">物品名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_goods" placeholder="请输入物品名称" name="goods" />
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label" for="edit_Userid" style="float:left;padding:7px 15px 0 27px;">发布人</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_Userid" name="userid" disabled="disabled">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label" for="edit_times" style="float:left;padding:7px 15px 0 27px;">发布日期</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_times" name="times" disabled="disabled">
						</div>
					</div>
					<div class="form-group">
						<label for="edit_types" class="col-sm-2 control-label">失物类型</label>
						<div class="col-sm-10">
							<select class="form-control" id="edit_types" name="types">
								<option selected>失物</option>
								<option>寻物</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label" for="edit_state" style="float:left;padding:7px 15px 0 27px;">状态</label> 
						<div class="col-sm-10">
							<input type="button" class="btn btn-primary" id="edit_state" name="state" onclick="Updatestate()">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label" for="edit_content" style="float:left;padding:7px 15px 0 27px;">详细信息</label> 
						<div class="col-sm-10">
							<textarea name="content" id="edit_content" rows="70" cols="50">
							</textarea>
							<script type="text/javascript">
							CKEDITOR.replace( 'edit_content',{
							toolbar:[
								['Source','-','Save','NewPage','Preview','-','Templates'],
								['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
								['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
								['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
								'/',
								['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
								['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
								['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
								['Link','Unlink','Anchor'],
								['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
								'/',
								['Styles','Format','Font','FontSize'],
								['TextColor','BGColor'],
								['Maximize', 'ShowBlocks','-','About']
							]
							});
							</script>
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateLosearticle()">保存修改</button>
			</div>
		</div>
	</div>
</div>
<!-- 管理员信息模态框 -->
<div class="modal fade" id="adminEditDialog1" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">管理员信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="admin_form">
					<input type="hidden" id="edit_id1" name="id"/>
					<div class="form-group">
						<label for="edit_adminName" class="col-sm-2 control-label" style="float:left;padding:7px 15px 0 27px;">名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_adminName1" placeholder="请输入管理员名称" name="admin_name" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_oldPassword" class="col-sm-2 control-label" style="float:left;padding:7px 15px 0 27px;">旧密码</label>
						<div class="col-sm-10"> 
							<input type="password" class="form-control" id="edit_Password" placeholder="请输入旧密码" name="password" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_newPassword" class="col-sm-2 control-label" style="float:left;padding:7px 15px 0 27px;">新密码</label>
						<div class="col-sm-10">
							<input type="password" class="form-control" id="edit_newPassword" placeholder="请输入新密码" name="newpassword" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateadmin()">保存修改</button>
			</div>
		</div>
	</div>
</div>
</body>
</html>